<?php
class pro_dt_pem_desain_promo_model extends MY_Model {
	var $model = 'pro_dt_pem_desain_promo';

	function GetJSON($as_pk_master)
	{
		$ls_sql	= "	SELECT	a.kode_desain,
					a.nama_desain,
					a.jenis_desain
					FROM	pro_dt_perm_pem_desain_promo a
					WHERE	a.kode_promo = '".$as_pk_master."' 
					ORDER BY ".(post('sort')=='' ? 'a.kode_desain' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order')); // ".$as_pk_master."

		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetailByID($as_pk_master)
	{
		$ls_sql	= "	SELECT	a.kode_desain,
					a.nama_desain,
					a.jenis_desain
					FROM	pro_dt_perm_pem_desain_promo a
					WHERE	a.kode_promo = '".$as_pk_master."' 
					ORDER BY kode_desain";
		
		$result	= $this->db->query($ls_sql);

		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}
	
	
	function Add($arr_data){
		$this->db->insert('pro_dt_perm_pem_desain_promo', $arr_data);	
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_dt_perm_pem_desain_promo', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('pro_dt_perm_pem_desain_promo', array('kode_desain' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('pro_dt_perm_pem_desain_promo', array('kode_desain' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			$this->db->delete('pro_dt_perm_pem_desain_promo', $arr_rule);
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>